package acwing;

import java.io.*;
import java.util.*;

public class ac854 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static final int N = 210, INF = 0x3f3f3f3f;
    static int n, m, k;
    static int[][] d = new int[N][N];

    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void floyd() {
        for (int k = 1; k <= n; k ++ ) {
            for (int i = 1; i <= n; i ++ ) {
                for (int j = 1; j <= n; j ++ ) {
                    d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        n = cin(); m = cin(); k = cin();
        for (int i = 1; i <= n; i ++ ) {
            for (int j = 1; j <= n; j ++ ) {
                if (i == j) d[i][j] = 0;
                else d[i][j] = INF;
            }
        }
        while (m -- > 0) {
            int x = cin(), y = cin(), z = cin();
            d[x][y] = Math.min(d[x][y], z);
        }
        floyd();
        while (k -- > 0) {
            int x = cin(), y = cin();
            int t = d[x][y];
            if (t > INF / 2) out.println("impossible");
            else out.println(t);
        }
        out.close();
    }
}
